package com.umeox.moto.watch.fitness.db.dao

import androidx.room.*
import com.umeox.moto.watch.fitness.db.model.ChallengeRecord

/**
 * Created by Rambo 2021/11/19
 * Describe:
 */
@Dao
interface ChallengeRecordDao {

    @Query("SELECT * FROM challenge_record WHERE isUpload = 0")
    fun loadAllNotUploadRecords() : MutableList<ChallengeRecord>?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun save(challengeRecord: ChallengeRecord): Long

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun update(challengeRecord: ChallengeRecord): Int

    @Query("SELECT * FROM challenge_record WHERE todayMillis = :todayMillis")
    fun loadTodayChallengeRecord(todayMillis:Int) :  MutableList<ChallengeRecord>?

    @Query("SELECT SUM(totalTime) FROM challenge_record WHERE todayMillis = :todayMillis AND totalTime > 0")
    fun getTodayActiveTime(todayMillis:Int) : Int

    @Query("DELETE FROM challenge_record")
    fun deleteAll(): Int
}